package com.lagouedu.kucun.consumer;


import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnBean(MessageListener.class)
public class RocketConsumer implements CommandLineRunner {

    private static final Logger logger = LoggerFactory.getLogger(RocketConsumer.class);

    @Autowired
    private MessageListener messageListener;

    @Override
    public void run(String... args) throws Exception {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer();
        consumer.setConsumerGroup("order-consume-grp");
        consumer.setNamesrvAddr("localhost:9876");
        // 配置消费主题
        consumer.subscribe("inventory_reduce_topic", "*");
        consumer.registerMessageListener(messageListener);
        consumer.start();
    }
}
